home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
172_01
/
lex.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
21KB
|
642 lines
/*
HEADER: CUG nnn.nn;
TITLE: LEX - A Lexical Analyser Generator
VERSION: 1.0 for IBM-PC
DATE: Jan 30, 1985
DESCRIPTION: A Lexical Analyser Generator. From UNIX
KEYWORDS: Lexical Analyser Generator YACC C PREP
SYSTEM: IBM-PC and Compatiables
FILENAME: LEX.C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: YACC and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: LATTICE C 3.0h
REFERENCES: UNIX Systems Manuals
*/
/*
* Copyright (c) 1978 Charles H. Forsyth
*/
/*
* lex -- initialisation, allocation, set creation
*
* Revised for PDP-11 (Decus) C by Martin Minow
*/
/* Modified 02-Dec-80 Bob Denny -- Conditionalized debug code for smaller size
* 01 -- Moved calls to dfa build, min, print, write
* and to stat, and code for ending() into
* this module so that 'ytab' could be put
* into overlay region.
* 29-May-81 Bob Denny -- More extern hacking for RSX overlaying.
* More 19-Mar-82 Bob Denny -- New C library & compiler
* More 03-May-82 Bob Denny -- Final touches, remove unreferenced autos
* 28-Aug-82 Bob Denny -- Add "-s" switch to supress references to
* "stdio.h" in generated code. Add switch
* comments in code. Add -e for "easy" com-
* mand line. "lex -e file" is the short way
* of saying:
* "lex -i file.lxi -o file.c -t file"
* More(!) 30-Oct-82 Bob Denny -- Fix RSX ODL to put lots of FCS junk into
* overlay, pick up (badly needed) 3KW for
* NFA nodes, etc. Change static allocations
* in LEXLEX.H for RSX so can do non-trivial
* things. Task is now big on RSX and grows
* from big to huge as it runs.
* Fix "-s" support so it is again possible
* to do a lexswitch() (dumb!).
* 14-Apr-83 Bob Denny VAX-11 C workarounds.
* Fix definition of toupper().
* 20-Nov-83 Scott Guthery Adapt for IBM PC & DeSmet C
* 22-Jun-86 Andrew Ward Adapted for Lattice C ver 3.0h. Debug and
* Error detection code installed as aid in
* detection of wild pointers which result
* from interchanging pointers and integers.
* The interchangable use of pointers and
* integers was eliminated.
*
* NOTICE: some Lattice 3.0 functions were used * However, these should be easy to recode.
* Non-ANSII functions will be removed latter
*
*/
#ifdef DOCUMENTATION
title lex A Lexical Analyser Generator
index A Lexical Analyser Generator
synopsis
lex [-options] [-i grammar] [-o outfile] [-t table]
description
Lex compiles a lexical analyser from a grammar and description of
actions. It is described more fully in lex.doc: only usage is
described. The following options are available:
.lm +16
.s.i-16;-a Disable recognition of non-ASCII characters
(codes > 177 octal) for exception character classes (form [^ ...]).
.s.i-16;-d Enable debugging code within lex. Normally
needed only for debugging lex.
.s.i-16;-e "Easy" command line. Saying "lex#-e#name" is the
same as saying:
.s.i 4;"lex -i name.lxi -o name.c -t name"
.s
Do not include devices or an extension on "name" or make it longer
than 8 characters, or you'll get several error messages.
.s.i-16;-i file Read the grammar from the file. If "-i" is not
specified, input will be read from the standard input.
.s.i-16;-m Enable state minimization. Currently not
implemented, switch is a no-op.
.s.i-16;-o file Write the output to the file. If "-o" is not
specified, output will be written to file "lextab.c".
.s.i-16;-s "Stand-alone" switch. Supresses the line
"#include <stdio.h>" normally generated in the lex output. Use this
if LEX is generating a module to be used in a program which does not
use the "standard I/O" package.
.s.i-16;-t table Name the recognizer "table" instead of the
default "lextab". If -o is not given, output will be written to file
"table.c".
.s.i-16;-v [file] Verify -- write internal tables to the
indicated file. If "-v" is given without a file name argument,
tables will be written to "lex.out".
.lm -16
diagnostics
The following error messages may occur on invocation. See lex
documentation for information on compilation errors.
.lm +8
.s.i -8;Can't create ...
.s.i -8;Cannot open ...
.s.i -8;Illegal option.
.s.i -8;Illegal switch combination.
.s
"-i", "-o" or "-t" given with "-e" or vice-versa
.s.i -8;Table name too long.
.s
The table name (argument to "-t") must not be longer than 8 bytes.
.s.i -8;Missing table name.
.s.i -8;Missing input file.
.s.i -8;Missing output file.
.s.i -8;Missing name.
.lm -8
author
Charles Forsyth
Modified by Martin Minnow, Bob Denny & Scott Guthery
Modified by Andrew M. Ward, Jr.
bugs
#endif
/*
* LEX -- Lexical scanner acquired from C-users group.
* In original form this program was an example of what good C
* programing is NOT. I have tried to eliminate machine dependancies
* where ever possible. In particular, the interchangable use of
* pointers and ints has been eliminated. External fuctions are declared
* with argument typed.
* 1986
* 02 June AMW: installed Lattice 3.0 functions in place of some combersom routines
* used by original code.
* 04 June routine lexsort: qsort replaced with call to Lattice function of same name.
* Result: LEX produces output with proper appearance, but does not
* compile correctly. Dangaling pointer is cause.
* 22 June My substitution code for NEWCCL was faulty. Original code replaced
* and system behaved properly. Further, using C-terp it was determined
* that the routine lexswitch returned the wrong value, this was corrected.
* 23 June modifications made to DEBUG segments. Program LEX produces compilable
* output that functions for word.lxi -> word.c as intended. hword.lxi
* does not process to completion. Symptom: lex hangs-up while displaying
* XX nets NN. The offending code is the DEBUG segment and the surrounding
* loop. Assert lines were installed but detected no errors.
* 24 June Newset modified to use sqsort() when routine called for DFA request.
* This modification may improve execution speed.
* 25 June The program now compiles and produces functional code for hword.lxi
* and word.lxi. Both programs fuction correctly. Further, I uncovered
* an error in the debug code I installed. It appears that certain control
* codes disable ANSI.SYS and the display can not be restarted. The code
* is in BASE.C and is identified by the UDEBUG segment.
*
*/
#include <stdio.h>
#include "lexlex.h"
#ifdef LATTICE
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
/* Set memory size for procedure. Lattic